<?php
$_act = $this->getAction()->getId();
if ($_act == 'create'):
	$this->pageTitle = '创建角色';
	$_disabled = array();
else:
	$this->pageTitle = '更新角色';
	$_disabled = array('disabled' => 'disabled');
endif;
?>
<?php echo EHtml::beginForm();?>
<fieldset>
  <legend><?php echo $this->pageTitle;?></legend>
  <table class="post">
    <tbody>
      <tr>
        <td width="100"><?php echo EHtml::activeLabelEx($model,'id'); ?></td>
        <td>
          <?php echo EHtml::activeTextField($model, 'id', $_disabled)?>
        </td>
      </tr>
      <tr>
        <td><?php echo EHtml::activeLabelEx($model,'honor'); ?></td>
        <td><?php echo EHtml::activeTextField($model, 'honor')?></td>
      </tr>
      <tr>
        <td><?php echo EHtml::activeLabelEx($model,'acls'); ?></td>
        <td>
          <?php foreach ($menu as $ctrlKey => $ctrl):?>
          <ul class="acl">
            <li class="ctrl"><label><input type="checkbox" name="ctrls[]" value="<?php echo $ctrlKey;?>" <?php if (isset($acls['ctrls'][$ctrlKey])): echo 'checked="true"'; endif;?> /><span><?php echo $ctrl['title'];?></span></label></li>
            <?php if (is_array($ctrl['actions'])):?>
            <li class="acts">
              <?php foreach ($ctrl['actions'] as $actKey => $act):?>
              <?php if (!isset($act['acl']) || $act['acl'] !== false):?>
              <label><input type="checkbox" name="acts[]" value="<?php echo $ctrlKey . '/' . $actKey;?>" <?php if (!isset($acls['ctrls'][$ctrlKey]) && isset($acls['acts'][$ctrlKey][$actKey])): echo 'checked="true"'; endif;?> /><span><?php echo $act['title'];?></span></label>
              <?php endif;?>
              <?php endforeach;?>
            </li>
            <?php endif;?>
          </ul>
          <?php endforeach;?>
        </td>
      </tr>
      <tr>
        <td><input type="submit" value="提交" /></td>
        <td></td>
      </tr>
    </tbody>
  </table>
</fieldset>
<?php echo EHtml::endForm();?>

<?php $this->beginJs();?>
<script type="text/javascript">

$('li.ctrl input:checkbox').click(function(e) {
	if (this.checked) {
		$(this).closest('ul')
			.find('li:last input:checkbox')
			.each(function(i, el) {
				this.checked = false;
			});
	}
});
$('li.acts input:checkbox').click(function(e) {
	$(this).closest('ul')
		.find('li:first input:checkbox')
		.each(function(i, el) {
			this.checked = false;
		});
});
</script>
<?php $this->endJs();?>